package com.sdkx.app.datalayers;

import android.content.Context;
import android.graphics.Canvas;

import cn.creable.gridgis.controls.ICustomDraw;
import cn.creable.gridgis.controls.ICustomDraw2;
import cn.creable.gridgis.controls.ICustomDrawDataCenter;
import cn.creable.gridgis.controls.MapControl;
import cn.creable.gridgis.display.Display;
import cn.creable.gridgis.geometry.Arithmetic;
import cn.creable.gridgis.geometry.IEnvelope;
import cn.creable.gridgis.geometry.IGeometry;
import cn.creable.gridgis.geometry.LineString;
import cn.creable.gridgis.geometry.Point;

public abstract class MapDraw implements  ICustomUpdata,ICustomDraw, ICustomDraw2, ICustomDrawDataCenter {
    MapControl mapControl;
    Context appContext;
    protected Point mDefaultPoint = new Point(116.156985, 40.065789);

    public MapDraw(Context context) {
        appContext = context;
    }

    public void setMapControl(MapControl control) {
        mapControl = control;
    }

    @Override
    public void drawOnMapCache(Canvas canvas) {
        if (mapControl != null)
            draw2(canvas, (Display) mapControl.getDisplay());
    }

    @Override
    public void drawOnScreen(Canvas canvas) {
        if (mapControl != null)
            draw2(canvas, (Display) mapControl.getDisplay());
    }

    @Override
    public IGeometry getGeometry(int i) {
        return null;
    }

    @Override
    public int getGeometryNum() {
        return 0;
    }

    @Override
    public void onGeometrySelected(int i, IGeometry iGeometry) {

    }

    @Override
    public void draw(Canvas canvas) {

    }

    protected abstract void draw2(Canvas canvas, Display display);

    @Override
    public void upData() {

    }
    protected LineString getCircleLines(Point center,double radius){
        double length = 111.1 * Math.cos(center.getY() * Math.PI / 180);
        double lon = center.getX() + radius / length;
        double lat = center.getY();
        Point oncercal = new Point(lon, lat);
        return  Arithmetic.makeCircle(center,oncercal,180);
    }
    protected boolean isInScreen(double lon,double lat){
        IEnvelope iEnvelope = mapControl.getExtent();
        boolean xMax = iEnvelope.getXMax()> lon;
        boolean xMin = iEnvelope.getXMin() < lon;
        boolean yMax = iEnvelope.getYMax() > lat;
        boolean yMin = iEnvelope.getYMin() < lat;
        return (xMax&& xMin&& yMax&& yMin);
    }
}
